package com.example.blog.config;

import com.example.blog.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ExceptionAdvice{
    @ExceptionHandler
    public Result<Object> handlerException(Exception e){
        log.error("发生异常 e: ", e);
        return Result.failure("内部错误");
    }

    @ExceptionHandler
    public Result<Object> handlerException(NoResourceFoundException e){
        log.error("发生异常 {} ", e.getMessage());
        return Result.failure("内部错误");
    }
}
